#include<stdio.h>
#include<string.h>
#include<ctype.h>

char s[85];

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        scanf("%s", s);
        int n = strlen(s);
        double sum = 0;
        int i = 0;
        while(i < n){
            double w = 0;
            char temp = s[i];
            if(temp == 'C') w = 12.01;
            if(temp == 'H') w = 1.008;
            if(temp == 'O') w = 16.00;
            if(temp == 'N') w = 14.01;

            if(isdigit(s[i + 1]) && isdigit(s[i + 2])){
                sum = sum + w * ((s[i + 1] - '0') * 10 + s[i + 2] - '0');
                i += 3;
            }else if(isdigit(s[i + 1]) && !isdigit(s[i + 2])){
                sum += w * (s[i + 1] - '0');
                i += 2;
            }else{
                sum += w;
                i += 1;
            }
        }
        printf("%.3lf\n", sum);
    }
}
